package com.liyiruo.tx.service.main14;

import com.liyiruo.tx.mapper.TableAMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 结果是a1,a2存储成功，b1和b2存储失败，因为调用方catch了被调方的异常，所以只有子事务回滚了。
 *
 * @author liyiruo
 * @Description
 * @Date 2022/2/18 下午5:11
 */
@Service
public class TestMain14 {

    @Autowired
    private TableAMapper tableAMapper;
    @Autowired
    private TestBe testBe14;

    @Transactional(propagation = Propagation.REQUIRED)
    public void testMain() {
        tableAMapper.addTableA();  //调用A入参a1
        try {
            testBe14.testB();    //调用testB
        } catch (Exception e) {
            System.out.println("=================");
        }
        tableAMapper.addTableA();  //调用A入参a1
    }
}
